using System;
using System.Collections.Generic;
using System.Text;
using JobShopModel.Model.FactoryLvl;

namespace JobShopModel.Model.JobLvl
{
    /// <summary>
    /// Statistics kept for Job class
    /// </summary>
    public class JobStats
    {
        //number completed for each type of job
        private Dictionary<JobTypes, int> jobCounter;
        //number created for each type of job
        private Dictionary<JobTypes, int> jobCreatedCounter;

        public Dictionary<JobTypes, int> JobCreatedCounter
        {
            get { return jobCreatedCounter; }
        }

        //total time spent waiting for transport by each job type
        private Dictionary<JobTypes, Time> totalDelayFifoTransp;
        //total time waiting at a station while all machines are occupied
        private Dictionary<JobTypes, Time> totalDelayQueueStation;
        //total time spent in transit
        private Dictionary<JobTypes, Time> totalTransporterDelay;

        //average time waiting for transport for this job type
        private Dictionary<JobTypes, Time> avgDelayFifoTransp;
        //average time in transit for this job type
        private Dictionary<JobTypes, Time> avgTransporterDelay;
        //average time waiting while all machines occupied for this job type
        private Dictionary<JobTypes, Time> avgDelayQueueStation;

        public int JobTypeNumber
        {
            get { return 3; }
        }

        public Dictionary<JobTypes, Time> TotalDelayFifoTransp
        {
            get { return totalDelayFifoTransp; }
        }
        public Dictionary<JobTypes, Time> TotalDelayQueueStation
        {
            get { return totalDelayQueueStation; }
        }

        public Dictionary<JobTypes, Time> TotalTransporterDelay
        {
            get { return totalTransporterDelay; }
        }

        public Dictionary<JobTypes, Time> AvgDelayFifoTransp
        {
            get { return avgDelayFifoTransp; }
        }       

        public Dictionary<JobTypes, Time> AvgDelayQueueStation
        {
            get { return avgDelayQueueStation; }
        }

        public Dictionary<JobTypes, Time> AvgTransporterDelay
        {
            get { return avgTransporterDelay; }
        }

        public Dictionary<JobTypes, int> JobCounter
        {
            get { return jobCounter; }

        }

        /// <summary>
        /// Converts total time members into averages based on the number of jobs of a given
        /// type that have been executed
        /// </summary>
        /// <param name="type">The job type for which the average is being calculated</param>
        public void CalculateAverage(JobTypes type)
        {
            this.avgDelayFifoTransp[type] = this.totalDelayFifoTransp[type] / jobCounter[type];
            this.avgDelayQueueStation[type] = this.totalDelayQueueStation[type] / jobCounter[type];
            this.avgTransporterDelay[type] = this.avgTransporterDelay[type] / jobCounter[type];
        }


        /// <summary>
        /// Default constructor
        /// </summary>
        public JobStats()
        {
            //Init the collections
            this.jobCounter = new Dictionary<JobTypes, int>();
            this.totalDelayFifoTransp = new Dictionary<JobTypes, Time>();
            this.totalDelayQueueStation = new Dictionary<JobTypes, Time>();
            this.totalTransporterDelay = new Dictionary<JobTypes, Time>();
            this.avgDelayFifoTransp = new Dictionary<JobTypes, Time>();
            this.avgDelayQueueStation = new Dictionary<JobTypes, Time>();
            this.avgTransporterDelay = new Dictionary<JobTypes, Time>();
            this.jobCreatedCounter = new Dictionary<JobTypes, int>();

            //Create the spots in Arrays
            this.jobCounter.Add(JobTypes.JOB1, 0);
            this.jobCounter.Add(JobTypes.JOB2, 0);
            this.jobCounter.Add(JobTypes.JOB3, 0);

            this.jobCreatedCounter.Add(JobTypes.JOB1, 0);
                this.jobCreatedCounter.Add(JobTypes.JOB2, 0);
                this.jobCreatedCounter.Add(JobTypes.JOB3, 0);


            this.totalTransporterDelay.Add(JobTypes.JOB1, new Time());
            this.totalTransporterDelay.Add(JobTypes.JOB2, new Time());
            this.totalTransporterDelay.Add(JobTypes.JOB3, new Time());

            this.totalDelayQueueStation.Add(JobTypes.JOB1, new Time());
            this.totalDelayQueueStation.Add(JobTypes.JOB2, new Time());
            this.totalDelayQueueStation.Add(JobTypes.JOB3, new Time());

            this.totalDelayFifoTransp.Add(JobTypes.JOB1, new Time());
            this.totalDelayFifoTransp.Add(JobTypes.JOB2, new Time());
            this.totalDelayFifoTransp.Add(JobTypes.JOB3, new Time());

            this.avgTransporterDelay.Add(JobTypes.JOB1, new Time());
            this.avgTransporterDelay.Add(JobTypes.JOB2, new Time());
            this.avgTransporterDelay.Add(JobTypes.JOB3, new Time());

            this.avgDelayQueueStation.Add(JobTypes.JOB1, new Time());
            this.avgDelayQueueStation.Add(JobTypes.JOB2, new Time());
            this.avgDelayQueueStation.Add(JobTypes.JOB3, new Time());

            this.avgDelayFifoTransp.Add(JobTypes.JOB1, new Time());
            this.avgDelayFifoTransp.Add(JobTypes.JOB2, new Time());
            this.avgDelayFifoTransp.Add(JobTypes.JOB3, new Time());



        }


    }
}
